package com.yoosora.utils;

import com.yoosora.common.mode.BasicDTO;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.commons.lang3.reflect.MethodUtils;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class DTOConvUtils {
	private static final String[] COPY_FIELDS = new String[]{"deleted", "createdId", "createdBy", "createdDate", "lastModifiedId", "lastModifiedBy", "lastModifiedDate", "creProId", "modProId", "batchDate"};

	public DTOConvUtils() {
	}

	public static void copyBasicProperties(Object src, BasicDTO tar) {
		try {
			if (src != null && tar != null) {
				String[] var2 = COPY_FIELDS;
				int var3 = var2.length;

				for(int var4 = 0; var4 < var3; ++var4) {
					String field = var2[var4];
					Field tarField = FieldUtils.getField(tar.getClass(), field, Boolean.TRUE);
					if (tarField != null) {
						Field srcField = FieldUtils.getField(src.getClass(), field, Boolean.TRUE);
						if (srcField != null) {
							String methodName = "set" + field.substring(0, 1).toUpperCase() + field.substring(1);
							Method method = MethodUtils.getAccessibleMethod(tar.getClass(), methodName, new Class[]{tarField.getType()});
							method.invoke(tar, srcField.get(src));
						}
					}
				}
			}

		} catch (Exception var10) {
			throw new RuntimeException(var10);
		}
	}
}